{% extends 'admin/public/base.html' %}

{% block title %}
<title>商品</title>
{% endblock %}

{% block con %}            


<div class="row">

    <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
        <div class="widget am-cf">
            <div class="widget-body  widget-body-lg am-fr">
                
                <!-- 内容区域 -->            
                <div class="row-content am-cf">
                    <div class="row">
                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                            <div class="widget am-cf">
                                <div class="widget-head am-cf">
                                    <div class="widget-title  am-cf">文章列表</div>
                                </div>
                                <div class="widget-body  am-fr">

                                    <div class="am-u-sm-12 am-u-md-6 am-u-lg-6">
                                        <div class="am-form-group">
                                            <div class="am-btn-toolbar">
                                                <div class="am-btn-group am-btn-group-xs">
                                                    <button type="button" class="am-btn am-btn-default am-btn-success"><span class="am-icon-plus"></span> 新增</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-secondary"><span class="am-icon-save"></span> 保存</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-warning"><span class="am-icon-archive"></span> 审核</button>
                                                    <button type="button" class="am-btn am-btn-default am-btn-danger"><span class="am-icon-trash-o"></span> 删除</button>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <form action="" method="get">
                                        <div class="am-u-sm-12 am-u-md-6 am-u-lg-3">
                                            <div class="am-form-group tpl-table-list-select">
                                                <select name="types" data-am-selected="{btnSize: 'sm'}">
                                                  <option {% if request.GET.types == 'all' %} selected {% endif %} value="all">所有类别</option>
                                                  <option {% if request.GET.types == 'title' %} selected {% endif %} value="title">商品标签</option>
                                                  <option {% if request.GET.types == 'num' %} selected {% endif %} value="num">商品库存(至少多少)</option>
                                                  <option {% if request.GET.types == 'clicknum' %} selected {% endif %} value="clicknum">商品点击量(至少多少点击量)</option>
                                                  <option {% if request.GET.types == 'tid_name' %} selected {% endif %} value="tid_name">所属分类</option>
                                                  <option {% if request.GET.types == 'status' %} selected {% endif %} value="status">状态</option>                                
                                                </select>
                                            </div>
                                        </div>
                                        <div class="am-u-sm-12 am-u-md-12 am-u-lg-3">
                                            <div class="am-input-group am-input-group-sm tpl-form-border-form cl-p">
                                                <input value="{{ request.GET.keywords }}" name="keywords" type="text" class="am-form-field">
                                                <span class="am-input-group-btn">
                                                    <button class="am-btn  am-btn-default am-btn-success tpl-table-list-field am-icon-search" ></button>
                                                 </span>
                                            </div>
                                        </div>
                                    </form>

                                    <table width="100%" class="am-table am-table-compact am-table-striped tpl-table-black " id="example-r">
                                        <thead>
                                            <tr>
                                                <th>商品缩略图</th>  
                                                <th>ID</th>>                      
                                                <th>商品标签</th>
                                                <th>商品价格</th>
                                                <th>商品库存</th>
                                                <th>商品点击量</th>
                                                <th>所属分类</th>
                                                <th>状态</th>                            
                                                <th>上架时间</th>
                                                <th>操作</th>                                                
                                            </tr>
                                        </thead>

                                        <tbody>
                                            {% for i in data %}
                                            {% if i.status != 3 %}
                                            <tr class="gradeX">                                               
                                                <td>
                                                    <img src="{{ i.pic }}" style="width: 30px">
                                                </td>
                                                <td class="id">{{ i.id }}</td>                                                                             
                                                <td>{{ i.title }}</td>
                                                <td>{{ i.price }}</td>
                                                <td>{{ i.num }}</td>                                                                                
                                                <td>{{ i.clicknum }}</td>
                                                <td>{{ i.tid.name }}</td>                                                
                                                <td>
                                                    {% if i.status == 0 %}
                                                        上架
                                                    {% elif i.status == 1 %}
                                                        热销
                                                    {% elif i.status == 2 %}
                                                        下架                                                                                                            
                                                    {% endif %}
                                                </td>
                                                <td>{{ i.addtime }}</td>
                                                <!-- 操作 -->
                                                <td>
                                                    <div class="tpl-table-black-operation">
                                                        <a href="{% url 'myadmin_good_setgood' %}?uid= {{ i.id }}">
                                                            <i class="am-icon-pencil"></i> 编辑
                                                        </a>
                                                        <a href="javascript:void(0)" class="tpl-table-black-operation-del">
                                                            <i class="am-icon-trash"></i> 删除
                                                        </a>
                                                    </div>
                                                </td>
                                            </tr>
                                            {% endif %}
                                            {% endfor %}      
                                        </tbody>
                                    </table>

                                    <div class="am-u-lg-12 am-cf">
                                        <div class="am-fr">
                                            <ul class="am-pagination tpl-pagination">                                                
                                                <!-- 导入 存放 自定义标签的.py文件 -->
                                                {% load pagetag %}                  
                                                <!-- 调用自定义过滤器                                                      
                                                    功能:1.显示标签
                                                        2.带跳转功能  
                                                    参数: 方法名字
                                                          showpage  

                                                          总页数
                                                          data.paginator.num_pages
                                                          
                                                          当前页数
                                                          request
                                                -->
                                                {% showpage data.paginator.num_pages request %}                                                                                   
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    // 删除当前数据 是讲当前数据  状态 ---> 3  3是不显示状态
    // 给删除按钮绑定 单机事件     
    $('.tpl-table-black-operation-del').click(function(){        
        // 获取  a标签的  父类组('tr')  查找 .id  的内容
        var id = $(this).parents('tr').find('.id').text()
        // 获取  a标签的  父类组('tr')  若在get里获取this 获取不到a标签
        var n = $(this).parents('tr')        

        $.get('{% url "myadmin_good_delete" %}',{'id':id},function(data){            
            if(data['pan'] == 1){
                // 删除页面 当前数据的标签
                n.remove()
                // 弹出返回 提示
                alert(data['jieguo'])
            }else {
                alert(data['jieguo'])
            }                        
        },'json')
    })
</script>


{% endblock %}      
